<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>Document</title>
  <link rel="stylesheet" href="./css/index.css" />
</head>

<body>
  <img src="./img/header.png" alt="" class="header" />
  <div class="cq-wrap">
    <!-- 导航 -->
    <div class="nav">
      <ul>
        <li><img src="./img/sword.png" alt="" /><span>剑士</span></li>
        <li><img src="./img/knight.png" alt="" /> <span>骑士</span></li>
        <li><img src="./img/Archer.png" alt="" /> <span>弓手</span></li>
        <li><img src="./img/hunter.png" alt="" /> <span>猎人</span></li>
        <li><img src="./img/magic.png" alt="" /> <span>法师</span></li>
        <li><img src="./img/flamen.png" alt="" /> <span>祭司</span></li>
      </ul>
    </div>
    <!-- table -->
    <table class="cq-list">
      <thead>
        <th>勇士</th>
        <th>技能</th>
        <th>武器</th>
      </thead>
      <tbody>
        <tr>
          <td>
            <img class="icon" src="http://p6.qhimg.com/dr/72__/t01b8063ea608652431.png" alt="" />
            <span>
              涅斯军长官尤莉娅
            </span>
          </td>
          <td>
            <img class="skill" src="http://p9.qhimg.com/dr/52__/t01087d8e61575ab25d.png" alt="" />
            注射!
          </td>
          <td>
            <img class="weapon" src="http://p6.qhimg.com/dr/45__/t0178ac936dcb72650f.png" alt="" />
            疫苗-G
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <!-- 遮罩层 -->
  <div class="cover" style="display: none">
    <img class="loading" src="./img/loading01.gif" alt="" />
  </div>
  <script src="./js/jquery-1.12.4.min.js"></script>
  <!-- 模板引擎 -->
  <script src="./js/template-web.js"></script>
  <!-- 模板 -->
  <script id="hero" type="text/html">
  {{each data.heros v}}
  <tr>
    <td>
      <img class="icon" src="{{v.heroIcon}}" alt="">
      <span>
        {{v.heroName}}
      </span>
    </td>
    <td>
      <img class="skill" src="{{v.skillIcon}}" alt="">
      {{v.skillName}}
    </td>
    <td>
      <img class="weapon" src="{{v.weaponIcon}}" alt="">
      {{v.weaponName}}
    </td>
  </tr>
  {{/each}}
</script>
  <script>
    $(function(){
      /*功能1:每隔6s,更新随机背景图*/
      setInterval(function(){
        $.ajax({
          url:'https://autumnfish.cn/api/cover/random',
          type:'get',
          dataType:'json',
          success: function(backData){
            console.log(backData);
            //显示背景图
            $("body").css("backgroundImage","url("+backData.url+")")
          }
        });
      },6000)

      /*功能2:点击每一个tab栏,tab栏切换*/
      $(".nav>ul>li").click(function(){
        //(1)排他思想修改样式
        $(this).addClass('active').siblings().removeClass();
        //(2)获取当前英雄类型
        let type=$(this).children('span').text();
        console.log(type);
        //(3)ajax发送请求
        $.ajax({
          url:'https://autumnfish.cn/api/cq/category',
          type:'get',
          dataType:'json',
          data:{type:type},
          success: function(backData){
            console.log(backData);
            //(4)渲染引擎页面
            $('table>tbody').html(template("hero",backData))
          }
        });
      })

      $("body").on("click",".icon",function(){
        //遮罩层
        $(".cover").show();
        $.ajax({
          url:'https://autumnfish.cn/api/cq/gif',
          type:'get',
          dataType:'json',
          data:{name:$(this).next().text().trim()},
          success: function(backData){
            
            $(".cover>img").attr("src",backData.data.skillGif)
            // $(".cover>img").show();
          }
        });
      })
      
      $(".cover").click(function(){
        $(this).fadeOut(function(){
          $(".cover>img").attr("src",'./img/loading01.gif')
        })
        // $(".cover>img").hide();
      })
    })
  </script>
</body>

</html>